﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Castle.ActiveRecord;
using Castle.Components.Validator;
namespace CastleDemo1.Model
{
    [ActiveRecord("Posts")]
    public class Post: ActiveRecordValidationBase<Post>
    {
        #region Mapping Property
        [PrimaryKey(PrimaryKeyType.GuidComb)]
        public Guid PostId { get; set; }
        [Property]
        public bool IsPublished { get; set; }
        [Property]
        [ValidateNonEmpty("标题不能为空")]
        public string Title { get; set; }
        [Property]
        public string Author { get; set; }
        [Property]
        public string PostContent { get; set; }
        [Property]
        public DateTime PublishDate { get; set; }
        [HasMany(Table="Comments", ColumnKey="PostId")]
        public IList<Comment> Comments { get; set; }


        #endregion

        public string ShortTitle 
        { 
            get
            {
                return Title.Length > 20 ? Title.Substring(0, 20) + "..." : Title;
            }
        }
        public string ShortContent
        {
            get
            {
                return PostContent.Length > 20 ? PostContent.Substring(0, 20) + "..." : PostContent;
            }
        }
    }
}